package com.spa.interfaces.admin;

import cn.dev33.satoken.annotation.SaIgnore;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.FinanceOrderListDTO;
import com.spa.application.dto.admin.FinanceOrderListExportDTO;
import com.spa.application.dto.admin.OrderDetailDTO;
import com.spa.application.query.admin.FinanceOrderQuery;
import com.spa.application.query.admin.OrderDetailQuery;
import com.spa.application.service.admin.AdminOrderService;
import com.spa.application.service.admin.FinanceApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("admin/finance")
public class AdminFinanceController extends BaseController {

    @Autowired
    private FinanceApplicationService financeApplicationService;

    @Autowired
    private AdminOrderService adminOrderService;

    @PostMapping("list")
    @SaIgnore
    public ResponseMessage<PageResult<FinanceOrderListDTO>> list(@RequestBody FinanceOrderQuery query) {
        return responseHelper.success(financeApplicationService.page(query));
    }

    @PostMapping("writeList")
    @SaIgnore
    public void writeList(HttpServletResponse response, @RequestBody FinanceOrderQuery query) throws Exception {
        List<FinanceOrderListExportDTO> records = financeApplicationService.list(query);
        exportQueryResult(response, records, "订单列表","订单列表",FinanceOrderListExportDTO.class);
    }

    @PostMapping("detail")
    public ResponseMessage<OrderDetailDTO> detail(@RequestBody OrderDetailQuery query) {
        return responseHelper.success(adminOrderService.detailById(query));
    }

}
